﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="AsiOtsing", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(AsiOtsing))]
    public class AsiOtsingSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IAsiOtsing clazz;
        
        public AsiOtsingSerializer(IAsiOtsing clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.EXCLUDE!=null) {
                Writer.WriteStartElement("EXCLUDE");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.EXCLUDE))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AsjaObjektID!=null) {
                Writer.WriteStartElement("AsjaObjektID");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.AsjaObjektID))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AsjaNR!=null) {
                Writer.WriteStartElement("AsjaNR");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AsjaNR))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AsjaLiikKL!=null) {
                Writer.WriteStartElement("AsjaLiikKL");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("long", "http://www.w3.org/2001/XMLSchema", clazz.AsjaLiikKL.Count);
                for (int x = 0; ((clazz.AsjaLiikKL != null) 
                            && (x < clazz.AsjaLiikKL.Count)); x = (x + 1)) {
                    if (clazz.AsjaLiikKL[x]!=null) {
                        Writer.WriteStartElement("item");
                        Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.AsjaLiikKL[x]))).ToString());
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.AsjaAlgusKP!=null) {
                Writer.WriteStartElement("AsjaAlgusKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.AsjaAlgusKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AsjaAlgusKPVahemikuLoppKP!=null) {
                Writer.WriteStartElement("AsjaAlgusKPVahemikuLoppKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.AsjaAlgusKPVahemikuLoppKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AsjaSeisundKL!=null) {
                Writer.WriteStartElement("AsjaSeisundKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.AsjaSeisundKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Menetlused!=null) {
                Writer.WriteStartElement("Menetlused");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("MenetlusOtsing", "http://producers.etoimik.xtee.riik.ee/producer/etoimik", clazz.Menetlused.Count);
                for (int x = 0; ((clazz.Menetlused != null) 
                            && (x < clazz.Menetlused.Count)); x = (x + 1)) {
                    if (clazz.Menetlused[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaMenetlused = this.GetMetaData(clazz.Menetlused[x]);
                        Writer.WriteTypeAttribute(metaMenetlused.TypeQualifiedName.Namespace, metaMenetlused.TypeQualifiedName.Name);
                        metaMenetlused.NewSerializer(clazz.Menetlused[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.Osalised!=null) {
                Writer.WriteStartElement("Osalised");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("OsalineOtsing", "http://producers.etoimik.xtee.riik.ee/producer/etoimik", clazz.Osalised.Count);
                for (int x = 0; ((clazz.Osalised != null) 
                            && (x < clazz.Osalised.Count)); x = (x + 1)) {
                    if (clazz.Osalised[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaOsalised = this.GetMetaData(clazz.Osalised[x]);
                        Writer.WriteTypeAttribute(metaOsalised.TypeQualifiedName.Namespace, metaOsalised.TypeQualifiedName.Name);
                        metaOsalised.NewSerializer(clazz.Osalised[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.ByrooOsalised!=null) {
                Writer.WriteStartElement("ByrooOsalised");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("OsalineOtsing", "http://producers.etoimik.xtee.riik.ee/producer/etoimik", clazz.ByrooOsalised.Count);
                for (int x = 0; ((clazz.ByrooOsalised != null) 
                            && (x < clazz.ByrooOsalised.Count)); x = (x + 1)) {
                    if (clazz.ByrooOsalised[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaByrooOsalised = this.GetMetaData(clazz.ByrooOsalised[x]);
                        Writer.WriteTypeAttribute(metaByrooOsalised.TypeQualifiedName.Namespace, metaByrooOsalised.TypeQualifiedName.Name);
                        metaByrooOsalised.NewSerializer(clazz.ByrooOsalised[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="EXCLUDE") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>AsiOtsing>EXCLUDE");
                }
                clazz.EXCLUDE = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("EXCLUDE")).Value;
            }
            if (Reader.LocalName=="AsjaObjektID") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsjaObjektID = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("AsjaObjektID")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AsjaNR") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsjaNR = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("AsjaNR")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AsjaLiikKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsjaLiikKL = new System.Collections.Generic.List<System.Int64?>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("AsjaLiikKL");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if (Reader.IsElementNil()) {
                                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>AsiOtsing>AsjaLiikKL>item");
                            }
                            clazz.AsjaLiikKL.Add(new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("item")).Value);
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AsjaAlgusKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsjaAlgusKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("AsjaAlgusKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AsjaAlgusKPVahemikuLoppKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsjaAlgusKPVahemikuLoppKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("AsjaAlgusKPVahemikuLoppKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AsjaSeisundKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsjaSeisundKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("AsjaSeisundKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Menetlused") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Menetlused = new System.Collections.Generic.List<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMenetlusOtsing>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("Menetlused");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if ((Reader.IsElementNil() == false)) {
                                global::Xtee.Core.SerializationMetadata metaMenetlused = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMenetlusOtsing>(Reader, "MenetlusOtsing", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                                global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMenetlusOtsing item = metaMenetlused.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMenetlusOtsing>();
                                clazz.Menetlused.Add(item);
                                if ((Reader.IsEmptyElement == false)) {
                                    Reader.ReadStartElement("item");
                                    metaMenetlused.NewSerializer(item).ReadXml(Reader);
                                    Reader.ReadEndElement();
                                }
                                else {
                                    Reader.Skip();
                                }
                            }
                            else {
                                clazz.Menetlused.Add(null);
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Osalised") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Osalised = new System.Collections.Generic.List<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IOsalineOtsing>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("Osalised");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if ((Reader.IsElementNil() == false)) {
                                global::Xtee.Core.SerializationMetadata metaOsalised = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IOsalineOtsing>(Reader, "OsalineOtsing", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                                global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IOsalineOtsing item = metaOsalised.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IOsalineOtsing>();
                                clazz.Osalised.Add(item);
                                if ((Reader.IsEmptyElement == false)) {
                                    Reader.ReadStartElement("item");
                                    metaOsalised.NewSerializer(item).ReadXml(Reader);
                                    Reader.ReadEndElement();
                                }
                                else {
                                    Reader.Skip();
                                }
                            }
                            else {
                                clazz.Osalised.Add(null);
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="ByrooOsalised") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.ByrooOsalised = new System.Collections.Generic.List<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IOsalineOtsing>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("ByrooOsalised");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if ((Reader.IsElementNil() == false)) {
                                global::Xtee.Core.SerializationMetadata metaByrooOsalised = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IOsalineOtsing>(Reader, "OsalineOtsing", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                                global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IOsalineOtsing item = metaByrooOsalised.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IOsalineOtsing>();
                                clazz.ByrooOsalised.Add(item);
                                if ((Reader.IsEmptyElement == false)) {
                                    Reader.ReadStartElement("item");
                                    metaByrooOsalised.NewSerializer(item).ReadXml(Reader);
                                    Reader.ReadEndElement();
                                }
                                else {
                                    Reader.Skip();
                                }
                            }
                            else {
                                clazz.ByrooOsalised.Add(null);
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
